package com.wang.metaObjectHandler.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Configuration;

/**
 * 自动填充配置类
 *
 * @author: wangning1@abupdate.com
 * @date: 2023-12-14 18:26
 **/
@Configuration
@Slf4j
public class AutoConfiguration implements MetaObjectHandler {
    /**
     * 插入时自动填充
     *
     * createUser 填充字段， create_admin 填充内容
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createUser", "create_admin", metaObject);
        this.setFieldValByName("updateUser", "update_admin", metaObject);
        log.info("插入时候自动填充");
    }

    /**
     * 更新时自动填充
     *
     * @param metaObject
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateUser", "update_admin", metaObject);
        log.info("更新时候自动填充");
    }
}